package com.weirdor.douyin;

import com.baidu.aip.face.AipFace;
import com.weirdor.douyin.utils.Base64ImageUtils;
import com.weirdor.douyin.utils.ResourceUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;
import java.util.HashMap;

/**
 *
 * @author weirdor
 */
public class DouYinStart


{
    //设置APPID/AK/SK
    public static final String APP_ID = "11298519";
    public static final String API_KEY = "BAix7Va8a0tHQiUtGxQqpBYS";
    public static final String SECRET_KEY = "w3F3kGOTCakO2LzsTrZ57GGBSyoX9L0q";


    public static void main(String[] args) throws IOException, InterruptedException {
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);
        //设置1000条抖音
        for (int x = 0; x < 1000; x++) {
            System.out.println("-----------------");
            System.out.println("这是第" + x + "个视频");
            HashMap<String, String> options = new HashMap<>();
            options.put("face_field", "age,gender,beauty,race");

            System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");
            String image = Base64ImageUtils.GetImageStrFromPath(ResourceUtils.getHack());
            Thread.sleep(3000);
            // 调用接口
            JSONObject res = client.detect(image, "BASE64", options);
            if (!res.get("result").equals(null)) {
                JSONObject jsonObject = res.getJSONObject("result");
                JSONArray array = jsonObject.getJSONArray("face_list");
                for (int i = 0; i < array.length(); i++) {

                    JSONObject jsonobject = array.getJSONObject(i);
                    JSONObject gender = jsonobject.getJSONObject("gender");
                    if (gender.getString("type").equals("male")) {
                        System.out.println("没有发现小姐姐，下一个");
                        SlideDownward();
                    } else if (gender.getString("type").equals("female")) {
                        System.out.println("❤️❤️❤️❤️");
                        System.out.println("年龄：" + array.getJSONObject(i).get("age"));
                        System.out.println("颜值：" + array.getJSONObject(i).get("beauty"));
                        int age = (int) array.getJSONObject(i).get("age");
                        double beauty = (double) array.getJSONObject(i).get("beauty");
                        //颜值大于40并且年龄大于18的小姐姐
                        if (beauty > 40 && age > 18) {
                            System.out.println("好可爱ヽ(✿ﾟ▽ﾟ)ノ 已喜欢❤");
                            Process processs = Runtime.getRuntime().exec("adb shell input tap 680 793");
                            processs.waitFor();
                            Thread.sleep(5000);
                        }
                        SlideDownward();
                    }


                }
            } else {
                SlideDownward();
                System.out.println("没有发现小姐姐，下一个");
            }

        }


    }

    /**
     * 向下滑动
     */
    public static void SlideDownward() {
        try {
            Process process = Runtime.getRuntime().exec("adb shell input swipe 540 1200 540 500 100");
            process.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
